/*********************************************************************************
 *      Copyright:  (C) 2022 Zhang Changxing<ZhangChangxingVIP@163.com>
 *                  All rights reserved.
 *
 *       Filename:  sms_send.h
 *    Description:  This file is used for function declarations.
 *                 
 *        Version:  1.0.0(05/1/2022)
 *         Author:  Zhang Changxing <ZhangChangxingVIP@163.com>
 *      ChangeLog:  1, Release initial version on "05/1/2022  01:33:25 AM"
 *                 
 ********************************************************************************/



#ifndef _SMS_SEND_H_
#define _SMS_SEND_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "serial_init.h"
#include "main.h"
#include "sms_pdu.h"



/*---------------------------------------------------------------------------
 *   description:   It is used to send the AT command, receive and judge the return information
 *          args:   $ttyusb_ctx:        Serial port property context
 *                  $at_buf:            A buffer that holds AT instructions
 *                  $expect_buf:        The string you expect to receive
 *                  $return_buf:        The address of the buffer that receives 
 *                  the returned information
 *                  $return_buf_len:   return_buf length
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int send_at_cmd(ttyusb_ctx_t *ttyusb_ctx, char *at_buf, const char *expect_buf, char *return_buf, int return_buf_len);


/*---------------------------------------------------------------------------
 *   description:   Check whether the serial port is available
 *          args:   $ttyusb_ctx:        Serial port property context
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int check_tyy_ready(ttyusb_ctx_t *ttyusb_ctx);


/*---------------------------------------------------------------------------
 *   description:   Check whether the SIM card exists
 *          args:   $ttyusb_ctx:        Serial port property context
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int check_sim_exist(ttyusb_ctx_t *ttyusb_ctx);


/*---------------------------------------------------------------------------
 *   description:   Check whether the SIM has been registered
 *          args:   $ttyusb_ctx:        Serial port property context
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int check_sim_login(ttyusb_ctx_t *ttyusb_ctx);


/*---------------------------------------------------------------------------
 *   description:   Check whether the SIM card signal is normal
 *          args:   $ttyusb_ctx:        Serial port property context
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int check_sim_signal(ttyusb_ctx_t *ttyusb_ctx);


/*---------------------------------------------------------------------------
 *   description:   Check whether the serial port and SIM are ready
 *          args:   $ttyusb_ctx:        Serial port property context
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int check_all_ready(ttyusb_ctx_t *ttyusb_ctx);


/*---------------------------------------------------------------------------
 *   description:   Check whether the serial port and SIM are ready
 *          args:   $ttyusb_ctx:    Serial port property context
 *                  $center_buf     Store the obtained center number
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int get_center_number(ttyusb_ctx_t *ttyusb_ctx, char *center_buf);


/*---------------------------------------------------------------------------
 *   description:   The Text format is used to send short messages
 *          args:   $ttyusb_ctx:    Serial port property context
 *                  $phone_buf      Store the obtained target number
 *                  $sms_buf        Information to be sent
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int send_text_sms(ttyusb_ctx_t *ttyusb_ctx, char *phone_buf, char *sms_buf);


/*---------------------------------------------------------------------------
 *   description:   Send short messages in PDU format
 *          args:   $ttyusb_ctx:    Serial port property context
 *                  $phone_buf      Store the obtained target number
 *                  $sms_buf        Information to be sent
 *  return value:   <0: failure,    =0: ok 
 *---------------------------------------------------------------------------*/
int send_pdu_sms(ttyusb_ctx_t *ttyusb_ctx, char *phone_buf, char *sms_buf);
#endif